 

import java.util.Scanner;
/**
 * CommonUIFunctions to use with the UI
 * @author Stefan
 */
public class CommonUIFunctions {

    /**
     * Pause the program
     */
    public static void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Press enter to continue");
        keyboard.nextLine();
    }

    /**
     *
     * @param toPrint String to print
     * @return int input from keyboard
     */
    public static int readInt(String toPrint)
    {
        int toRet = 0;
        Scanner keyboard = new Scanner(System.in);
        boolean ok = false;
        while(!ok)
        {
            System.out.print(toPrint);
            try
            {
                toRet = keyboard.nextInt();
                ok = true;
            }
            catch(Exception e)
            {
                System.out.println("Not a valid input, please try again");
                keyboard.nextLine();
                //pause();
            }
        }
        return toRet;
    }

    /**
     *
     * @param toPrint String to print
     * @return double input from keyboard
     */
    public static double readDouble(String toPrint)
    {
        double toRet = 0.0;
        Scanner keyboard = new Scanner(System.in);
        boolean ok = false;
        while(!ok)
        {
            System.out.print(toPrint);
            try
            {
                toRet = keyboard.nextDouble();
                ok = true;
            }
            catch(Exception e)
            {
                System.out.println("Not a valid input, please try again");
                keyboard.nextLine();
            }
        }
        return toRet;
    }

    /**
     *
     * @param toPrint String to print
     * @return String input from keyboard
     */
    public static String readString(String toPrint)
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print(toPrint);
        return keyboard.nextLine();
    }
}
